Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

746
Visualizações
How do I copy a static folder to both "dev" and "build" in Vite?

I'm trying to upgrade my Webpack based Vue.js project to Vite. I have folder structure like this:

 - src/
 - static/
 - tests/

In Webpack, I was using CopyWebPackPlugin like this:

new CopyWebpackPlugin([
  {
    from: path.resolve(__dirname, '../static'),
    to: '',
    ignore: ['.*']
  }
]),

And copied all files inside the static folder to make it available on both dev and build.

I'd like to do the same via Vite but can't figure out what how to implement it.

I tried the following code but it didn't work.

viteStaticCopy({
  targets: [
    {
      src: path.resolve(__dirname, '../static'),
      dest: '/'
    }
  ]
})
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The following changes should be an equivalent to your previous CopyWebpackPlugin settings:

  1. vite-plugin-static-copy does not support an explicit ignore option, but you can set the src glob pattern to exclude dotfiles.

  2. The dest should be './' to copy the files into the root of the output directory (default is dist).

import { defineConfig } from 'vite'
import { viteStaticCopy } from 'vite-plugin-static-copy'
import path from 'path'

export default defineConfig({
  plugins: [
    viteStaticCopy({
      targets: [
        {
          src: path.resolve(__dirname, './static') + '/[!.]*', // 1️⃣
          dest: './', // 2️⃣
        },
      ],
    }),
  ]
})

demo

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda